package cn.jiyun.kafka.producer;

import cn.jiyun.kafka.pojo.User;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;

public class HelloController {
    @Autowired private KafkaTemplate<String,String> kafkaTemplate;

    @GetMapping("/hello")
    public String  hello(){
        kafkaTemplate.send("kafka-hello-2111A","这是springboot整合kafka第一条消息");
        return "ok";
    }


    @GetMapping("/hello")
    public String  hello1(){
        User user = new User();
        user.setUsername("张三");
        user.setAge(18);
        kafkaTemplate.send("kafka-hello-user", JSON.toJSONString(user));
        return "ok";
    }
}
